|
|
|
|
|
|
|
The dwDesiredAccess constant allows you to specify a number of constants that define the type of access you wish. Whether you get that access depends on the permission available to the account you are using. Our sample will assume that the user is running as a system administrator, because anyone creating ASP pages and associated components is probably running as an administrator anyway. |
|
|
|
|
|
|
|
|
When you are finished with the Service Control Manager, you must close it using the CloseServiceHandle function, which is defined as follows: |
|
|
|
|
|
|
|
|
BOOL CloseServiceHandle( SC_HANDLE hSCObject // handle to service or service control manager database
); |
|
|
|
|
|
|
|
|
The CloseServiceHandle function is also used to close a service. |
|
|
|
|
|
|
|
|
The Service Control Manager is also used to open services using the following function: |
|
|
|
|
|
|
|
|
SC_HANDLE OpenService( SC_HANDLE hSCManager, // handle to service control manager database
LPCTSTR lpServiceName, // pointer to name of service to start
DWORD dwDesiredAccess // type of access to service
); |
|
|
|
|
|
|
|
|
The function returns a handle to a service. The dwDesiredAccess parameter allows you to specify which operations you wish to perform on the service. The service name is not the name displayed in the Control Panel's service control applet. That name is the "display name"a version that is designed to be easily understood. The actual service name can be obtained by enumerating the services using the EnumServicesStatus function, which follows: |
|
|
|
|
|
|
|
|
BOOL EnumServicesStatus( SC_HANDLE hSCManager, // handle to service control manager
database
DWORD dwServiceType, // type of services to enumerate
DWORD dwServiceState, // state of services to enumerate
LPENUM_SERVICE_STATUS lpServices, // pointer to service status buffer
DWORD cbBufSize, // size of service status buffer
LPDWORD pcbBytesNeeded, // pointer to variable for bytes needed
LPDWORD lpServicesReturned, // pointer to variable for number returned
LPDWORD lpResumeHandle // pointer to variable for next entry
); |
|
|
|
|
|
|
|
|
This function loads a structure called an ENUM_SERVICE_STATUS structure, which is defined as follows: |
|
|
|
|
|